<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>notify-pause-rule-add</title>
	<%@ include file="../include/common.jsp"%>
	<%@ include file="../include/jbox.jsp"%>
	<%@ include file="../include/form.jsp"%>
	 <script type="text/javascript" src="<%=request.getContextPath()%>/scripts/jsframework.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath()%>/scripts/Union/dateUtil.js"></script>
    <script src="<%=request.getContextPath()%>/js/calendar/zh_CN_WdatePicker.js"></script>
	<script src="${pageContext.request.contextPath}/js/crontab/Simple_util.js"></script>
	<script src="<%=request.getContextPath()%>/js/crontab/Crontab.js"></script>
	<script src="<%=request.getContextPath()%>/js/crontab/Crontab_data_zh_CN.js"></script>
    <script src="${pageContext.request.contextPath}/js/TimeUnit/TimeUnit.js"></script>
    <script src="${pageContext.request.contextPath}/js/TimeUnit/TimeUnit_data_zh_CN.js"></script>
	<style type="text/css">
		.tdValue{
			border: 1px solid #D6D3D6;
			line-height: 26px;
			height: 32px;
			padding-left: 5px;
			overflow: hidden;
		}
	</style>
	<script type="text/javascript">
	var tunit;
	function closewin(){
		  getTopWin(window).closejBox("add-pause-rule");
	  }
	function add(){
		 var startTime = ctd.results();
	     var duration = tunit.results();
			  if(duration == '0'){
				  getTopWin(window).getMessageBox().alert("持续时间不能为空","提示");
			  	  return;
			  }
			  var arrays = startTime.split(" ");
		        if ("?" == arrays[5]) {
		            if ("*" == arrays[3]) {
		            } else {
		                // 月暂停
		            	if(duration > 3600*24*31){
		            		getTopWin(window).getMessageBox().alert("有效时间选择按月后，持续时间不能超过一个月","提示");
		            		return;
			            }
		            }
		        } else {
		            // 说明是按星期
		            if(duration > 3600*24*7){
		            	getTopWin(window).getMessageBox().alert("有效时间选择按周后，持续时间不能超过一周","提示");
		            	return;
		            }
		        }
			  $.ajax({
				   type: "POST", 
				   url: "${pageContext.request.contextPath}/notify/notify-pause-rule!save.action?startTime="+startTime+"&duration="+duration, 
				   data: $("#myform").serialize(), //传的参数
				   dataType: 'json',
				   success: function(data){ //结果
						   var pWin = getTopWin(window).currentWin["add-pause-rule"];
						   pWin.datagrid();
						   getTopWin(window).closejBox("add-pause-rule");
				   }
			});
	}
	$(function(){
		tunit = new SimpleTimeUnit("divDuration","ddHHmm");
        tunit.show().isRequiredSymbol();
        ctd.setTU(tunit);
		$.formValidator.initConfig({formid:"myform"
	        ,onerror:function(msg){}
	        ,onsuccess:function(){
	      	  		add();
	        		return false;
	        }
	  	});
	})
	</script>
  </head>
  
  <body class="padding-8">
    <form action="" id="myform" name="myform" method="post">
    		<table class="table_eidt">
    			<tr style="height: 60px">
	    			<td class="td_left" width="100px">暂停方式</td>
	    			<td class="tdValue">
						 <div id="crontabTimeDiv"></div>
		                 <script type="text/javascript">
		                     var ctd = new Crontabs("crontabTimeDiv");
		                 </script>
					</td>
    			</tr>
    			<tr style="height: 60px">
	    			<td class="td_left">持续时间</td>
	    			<td class="tdValue">
	    				 <div id="divDuration"></div>
	    			</td>
    			</tr>
    		</table>
    		<div align="center" style="margin-top:5px;">
	    		<input type="submit" id="button" name="button" value="保存" class="btn-4">
	    		<input type="reset" class="btn-4" value="重置">
	    		<input type="button" value="取消" onclick="closewin();" class="btn-4">
    		</div>
    		<input type="hidden" id="notifyRuleId" name="notifyRuleId" value=${notifyRuleId}>
    	</form>
  </body>
</html>
